﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCService.Common.RedisClear;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Management.System.RedisOperation
{
    /// <summary>
    /// Redis缓存操作接口
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "Admin-SystemTools")]
    public class RedisOperationController : ManagementBaseController
    {
        private readonly IRedisClearService redisClearService;

        public RedisOperationController(IRedisClearService redisClearService)
        {
            this.redisClearService = redisClearService;
        }

        /// <summary>
        /// 清理所有缓存
        /// </summary>
        /// <response code="204">清理完毕。</response>
        /// <returns></returns>
        [HttpPut("[action]")]
        [Log("清理所有缓存")]
        public IActionResult FlushAll()
        {
            this.redisClearService.FlushAsync(null);
            return NoContent();
        }

        /// <summary>
        /// 当前数据库缓存总数
        /// </summary>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]/{id}")]
        public IActionResult Size([FromRoute(Name = "id")]int id)
        {
            return Ok(this.redisClearService.Size(id));
        }

        /// <summary>
        /// 获取Redis缓存服务器信息
        /// </summary>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        public IActionResult Info()
        {
            return Ok(this.redisClearService.Info(string.Empty));
        }

        /// <summary>
        /// 获取Redis缓存服务器信息
        /// </summary>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        public IActionResult InfoRaw()
        {
            return Ok(this.redisClearService.InfoRaw(string.Empty));
        }
    }
}
